package com.oracle.service.imple;

import com.oracle.dao.CommodityMapper;
import com.oracle.dao.ImageMapper;
import com.oracle.pojo.Commodity;
import com.oracle.pojo.Image;
import com.oracle.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("commmodityService")
public class CommodityServiceImple implements CommodityService {
    @Autowired
    private CommodityMapper commodityMapper;
    @Autowired
    private ImageMapper imageMapper;
    @Override
    public int saveComm(Commodity commodity) {
        return commodityMapper.insertSelective(commodity);
    }

    @Override
    public int saveImage(Integer id,String url) {
        Image image=new Image();
        image.setCommodityId(id);
        image.setUrl(url);
        return imageMapper.insertSelective(image);
    }

    @Override
    public int update(Commodity commodity) {
        return commodityMapper.updateByPrimaryKeySelective(commodity);
    }

    @Override
    public Commodity findCommodityById(Integer id) {
        return commodityMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Commodity> queryByCid(Integer id) {
        return commodityMapper.queryByCid(id);
    }

    @Override
    public List<Image> findImageByCid(int cid) {
        return imageMapper.findImageByCid(cid);
    }
}
